
cmake_minimum_required(VERSION 3.14.1)

if(${CMAKE_VERSION} VERSION_LESS 3.14.1 OR ${CMAKE_VERSION} VERSION_GREATER 3.26)
    message(FATAL_ERROR "CMake version must be between 3.14.1 and 3.26")
endif()

include(CMakePrintHelpers)

set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_CXX_STANDARD 14)

set(PROJECT_NAME https_demo)

project(${PROJECT_NAME})

set(SRC_DIR 
    ${CMAKE_CURRENT_SOURCE_DIR})

#手动添加源文件，更新进SRCS变量
set(SRCS 
${PROJECT_SOURCE_DIR}/Https_Demo.cpp
)

set(LIB_LIST 
    https_client
    curl
    ssl
    crypto
    pthread
    dl
    # z
)

include_directories(${PROJECT_SOURCE_DIR}/include)            

# Check if Architecture environment variable is set
if(DEFINED ENV{Architecture})
    set(Target_Architecture $ENV{Architecture})
else()
    # If Architecture environment variable is not set, set Target_Architecture based on CMAKE_HOST_SYSTEM_PROCESSOR
    if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
        set(Target_Architecture "x86_64")
    elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
        set(Target_Architecture "aarch64")
    else()
        message(FATAL_ERROR "Unsupported architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
    endif()
endif()

message("Target_Architecture: ${Target_Architecture}")

add_subdirectory(src)

link_directories(${PROJECT_SOURCE_DIR}/lib/${Target_Architecture})

#自动搜索源文件，增量更新进SRCS变量
# aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}  SRCS)

add_compile_options(-Wall -O0 -g )

add_executable(${PROJECT_NAME} ${SRCS})

target_link_libraries(${PROJECT_NAME} PRIVATE ${LIB_LIST})

install(TARGETS ${PROJECT_NAME} DESTINATION ${PROJECT_SOURCE_DIR}/out)